﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using Sebastof.Services.Interfaces;

#endregion

namespace Sebastof.Client.Services.Impl {
	/// <summary>
	/// Description of the class
	/// </summary>
	public class ObservableList<T> : List<T>, IList<T> {
		#region Public Properties

		// public Properties located here

		#endregion

		#region Public Methods

		public ObservableList(IAppliedChangesOnObjectsCollectorService observer, Object parent, string keyOnParent) {
			m_observer = observer;
			m_parent = parent;
			m_keyOnParent = keyOnParent;
		}

		public new void Add(T item) {
			m_observer.DepositeObjectAddedEntry(item, m_parent, m_keyOnParent);
			base.Add(item);
		}

		public new void Insert(int index, T item) {
			m_observer.DepositeObjectAddedAtEntry(index, item, m_parent, m_keyOnParent);
			base.Insert(index, item);
		}

		public void Add(object item) {
			m_observer.DepositeObjectAddedEntry(item, m_parent, m_keyOnParent);
			base.Add((T)item);
		}

		public new bool Remove(T item) {
			m_observer.DepositeObjectRemovedEntry(item, m_parent, m_keyOnParent);
			return base.Remove(item);
		}

		public new void RemoveAt(int index) {
			m_observer.DepositeObjectRemovedAtEntry(index, m_parent, m_keyOnParent);
			base.RemoveAt(index);
		}

		public bool Remove(Object o) {
			return Remove((T)o);
		}

		#endregion

		#region Private Methods

		// private methods located here

		#endregion

		#region Private Fields

		private readonly string m_keyOnParent;
		private readonly IAppliedChangesOnObjectsCollectorService m_observer;
		private readonly Object m_parent;

		#endregion

		#region IList<T> Members

		int IList<T>.IndexOf(T item) {
			return base.IndexOf(item);
		}

		void IList<T>.Insert(int index, T item) {
			Insert(index, item);
		}

		void IList<T>.RemoveAt(int index) {
			RemoveAt(index);
		}

		T IList<T>.this[int index] {
			get { return base[index]; }
			set {
				base[index] = value;
				;
			}
		}

		void ICollection<T>.Add(T item) {
			Add(item);
		}

		void ICollection<T>.Clear() {
			Clear();
		}

		bool ICollection<T>.Contains(T item) {
			return base.Contains(item);
		}

		void ICollection<T>.CopyTo(T[] array, int arrayIndex) {
			base.CopyTo(array, arrayIndex);
		}

		int ICollection<T>.Count {
			get { return base.Count; }
		}

		bool ICollection<T>.IsReadOnly {
			get { return false; }
		}

		bool ICollection<T>.Remove(T item) {
			return Remove(item);
		}

		IEnumerator<T> IEnumerable<T>.GetEnumerator() {
			return base.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return base.GetEnumerator();
		}

		#endregion
	}
}